package com.cuif.ioc.customEditor;


import org.springframework.beans.propertyeditors.ClassEditor;

import com.cuif.pojo.Address;

/**
 * 地址编辑器
 * @author cuif
 *
 */
public class AddressEditor extends ClassEditor{

	@Override
	public void setAsText(String text) throws IllegalArgumentException {
		if(text == null || "".equals(text)){
			this.setValue(null);
			return ;
		}
		
		String[] textSplit = text.split("-");
		if(textSplit == null || textSplit.length < 5){
			this.setValue(null);
			return ;
		}
		
		Address address = new Address();
		address.setCountry(textSplit[0]);
		address.setProvince(textSplit[1]);
		address.setCity(textSplit[2]);
		address.setArea(textSplit[3]);
		address.setStreet(textSplit[4]);
		this.setValue(address);
	}
	
}
